package com.xwh.week5;

import java.util.ArrayList;

public class Pr_10 {
    public static boolean isprime(int n) {
        for (int i = 2; i * i <= n; i++)
            if (n % i == 0) return false;
        return true;
    }

    public static int prime() {
        ArrayList<Integer> res1 = new ArrayList<>();
        ArrayList<Integer> res2 = new ArrayList<>();
        int i, j, value = 0, count = 0;
        for (i = 2; i < 1000; i++) {
            int n = 0, t = 0;
            for (j = i; ; j++) {
                if (isprime(j)) {
                    t += j;
                    n++;
                    if (t < 1000000) {
                        if (isprime(t)) {
                            value = t;
                            count = n;
                        }
                    } else break;
                }
            }
            res1.add(value);
            res2.add(count);
        }
        int max = 0, i1 = 0;
        for (i = 0; i < res2.size(); i++) {
            if (res2.get(i) > max) {
                max = res2.get(i);
                i1 = i;
            }
        }
        return res1.get(i1);
    }

    public static void main(String[] args) {
        System.out.println(prime());
    }
}
